﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using DaiKin.DBDataAccessLib.Helper;
using System.Data.OracleClient;
using System.Data;
using System.Data.SqlClient;
using DBDataAccessLib.DataMapping;

namespace DBDataAccessLib
{
    public abstract class LineNameDataAccess
    {
        public static Dictionary<string, string> GetLinesByJIBU(string jibu)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            DbDataReader reader;
            if (DBHelperFactory.DbName == DBType.Oracle)
                reader = OracleHelper.ExecuteReader(
                    OracleHelper.ConnectionStringLocalTransaction,
                    CommandType.Text,
                    SqlProvider.SelectedRecordsByJIBU,
                    new OracleParameter(":jibu", jibu)
                    );
            else
                reader = SqlHelper.ExecuteReader(
                SqlHelper.ConnectionStringLocalTransaction,
                CommandType.Text,
                SqlProvider.SelectedRecordsByJIBU,
                new SqlParameter("@jibu", jibu)
                );
            while (reader.Read())
            {
                dic.Add(reader.GetString(1).Trim(), reader.GetString(0).Trim());
            }
            return dic;
        }

        public static List<string> GetLineCodesByJIBU(string jibu)
        {
            List<string> li = new List<string>();
            DbDataReader reader;
            if (DBHelperFactory.DbName == DBType.Oracle)
                reader = OracleHelper.ExecuteReader(
                    OracleHelper.ConnectionStringLocalTransaction,
                    CommandType.Text,
                    SqlProvider.SelectedRecordsByJIBU,
                    new OracleParameter(":jibu", jibu)
                    );
            else
                reader = SqlHelper.ExecuteReader(
                SqlHelper.ConnectionStringLocalTransaction,
                CommandType.Text,
                SqlProvider.SelectedRecordsByJIBU,
                new SqlParameter("@jibu", jibu)
                );
            while (reader.Read())
            {
                li.Add(reader.GetString(1).Trim());
            }
            return li;
        }
    }

    public abstract class GSVXDataAccess
    {
        public static List<Pair<string, string>> GetSebangoMappings()
        {
            List<Pair<string, string>> pairs = new List<Pair<string, string>>();
            DbDataReader reader;
            if (DBHelperFactory.DbName == DBType.Oracle)
                reader = OracleHelper.ExecuteReader(
                    OracleHelper.ConnectionStringLocalTransaction,
                    CommandType.Text,
                    SqlProvider.SelectedGSVXRecords
                    );
            else
                reader = SqlHelper.ExecuteReader(
                SqlHelper.ConnectionStringLocalTransaction,
                CommandType.Text,
                SqlProvider.SelectedGSVXRecords
                );
            while (reader.Read())
            {
                pairs.Add(new Pair<string, string>
                {
                    Val1 = reader.GetString(1).Trim(),//sebango
                    Val2 = reader.GetString(0).Trim()//model
                });
            }
            return pairs;
        }
    }
}
